package cn.onlineclass.service;

import cn.onlineclass.dao.OMajorMapper;
import cn.onlineclass.entity.OMajor;
import cn.onlineclass.util.AjaxPage;
import cn.onlineclass.util.AjaxResult;
import cn.onlineclass.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class OMajorService {
    public static final OMajorService INST=new OMajorService();
    public AjaxPage search(int pageNo, int pageSize, boolean inuse, long ratationid) {
        SqlSession s = MybatisUtil.get();
        try {
            OMajorMapper mapper = s.getMapper(OMajorMapper.class);

            List<OMajor> search = mapper.search(pageNo, pageSize,inuse,ratationid);
            int total = mapper.searchTotal(inuse,ratationid);
            return new AjaxPage(search,total,pageNo,pageSize);
        } finally {
            MybatisUtil.closeSession(s);
        }
    }
    public int add(OMajor oMajor){
        SqlSession session = MybatisUtil.get();
        try {
            OMajorMapper mapper = session.getMapper(OMajorMapper.class);
            return mapper.add(oMajor);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }

    public OMajor get(long id){
        SqlSession session = MybatisUtil.get();
        try {
            OMajorMapper mapper = session.getMapper(OMajorMapper.class);
            return mapper.get(id);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }

    public int update(OMajor oMajor){
        SqlSession session = MybatisUtil.get();
        try {
            OMajorMapper mapper = session.getMapper(OMajorMapper.class);
            return mapper.update(oMajor);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }

    public int del(OMajor oMajor){
        SqlSession session = MybatisUtil.get();
        try {
            OMajorMapper mapper = session.getMapper(OMajorMapper.class);
            return mapper.del(oMajor);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }
}
